package my.sample.cassandra;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.apache.commons.lang3.StringUtils;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;

public class SyslogInsert {

	/**
	 * @param args
	 */
	
	static Cluster cluster;
	static Session session;
	
	public static void main(String[] args) {
		
		
/*		cluster = Cluster.builder().addContactPoint("119.226.225.237").build();
		session = cluster.connect("beacon");
		
		System.out.println(session.isClosed());
		String name = "venu";
		int id = 20;
		
		session.execute("INSERT INTO table1 (id, name) VALUES (" + id + "," + name + ")");
		
		System.exit(1);
		
		
		StringUtils utils = new StringUtils();*/
		
		
		try {
			BufferedReader br = new BufferedReader(new FileReader("/tmp/cc/test.log"));
			String line;
			
			while ((line = br.readLine()) != null) {
				// process the line.
			
				if (!line.contains("CSCOacs_RADIUS_Accounting"))
					continue;
//				String[] fields = line.split(",");
				
				String[] fields  = StringUtils.split(line, ",");
				System.out.println(line);
				
				
				System.out.println(StringUtils.indexOf(line, "ACSVersion="));
				System.out.println(StringUtils.substring(line, StringUtils.indexOf(line, "ACSVersion=") +  10 , StringUtils.indexOf(line, "ACSVersion=") +  10 + 50));
//				fields[0].ind
//				System.out.println(Arrays.toString(fields));
				System.out.println(fields.length);
				System.out.println(fields[1]);
//				sysout
				
			}
			br.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		

	}
	
	private String findValueTillComa( String line, String key ) {
		
/*		int start = StringUtils.indexOf(line, key);
		int stop = StringUtils.ind
		StringUtils.substring(line, start + key.length(), )*/
		
		return "";
		
	}
	
	
}
